/**
 * Created by Amaris on 2016/12/6.
 */


var util = require('../utils/util.js');
var evaluateClass = require('../class/evaluate.js');

module.exports = {


    getCountById: function (params, cb) {
        var models = util.models;

        if (!models) {
            var err = new Error();
            err.status = 500;
            err.message = '数据库连接失败';
            cb(err, null);
            return;
        }

        var evaluate = new evaluateClass();

        var checkResult = evaluate.checkParams(['rowId'], params);
        if (checkResult) {
            cb(null, util.getErrorRes('400', checkResult));
            return;
        } else {
            evaluate.init(params);
        }

        models.evaluate.findOne(evaluate.getParams(), function (err, data) {
            if (err || !data) {
                console.log(err.message);
                var err = new Error();
                err.status = 500;
                err.message = '系统错误';
                cb(err, null);
                return;
            }

            cb(null, util.getSuccessRes(data));

        });
    },
    getCountList:function(params,cb){

        var models=util.models;

        if(!models){
            var err=new Error();
            err.status=500;
            err.message="数据库连接失败";
            cb(err,null);
            return;
        }
        models.evaluate.find().exec(function (err, data){
            if (err || !data) {
                var err = new Error();
                err.status = 500;
                err.message = '系统错误';
                cb(err, null);
                return;
            }
            cb(null, util.getSuccessRes(data));
        });

    },
    getEvaluateInfoList:function(params,cb){

        var models=util.models;

        if(!models){
            var err=new Error();
            err.status=500;
            err.message="数据库连接失败";
            cb(err,null);
            return;
        }
        models.evaluate.find().exec(function (err, data){
            if (err || !data) {
                var err = new Error();
                err.status = 500;
                err.message = '系统错误';
                cb(err, null);
                return;
            }
            cb(null, util.getSuccessRes(data));
        });

    }
};



